package cn.com.chec.en.controller.front;

import cn.com.chec.en.dao.PageLinkDao;
import cn.com.chec.en.util.ContactUtils;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ErrorFrontController {
	protected static final Logger logger = Logger
			.getLogger(ErrorFrontController.class);

	@Resource
	private PageLinkDao pageLinkDao;

	@Resource
	private Map<String, Object> environment;

	@RequestMapping(value = { "/error" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET })
	public ModelAndView error(
			@RequestParam(value = "code", required = false) String code,
			HttpServletRequest request, HttpServletResponse response,
			ModelMap map) throws Exception {
		String view = "error";

		map.put("pageLinkMap", this.pageLinkDao.getAllAsMap());

		map.putAll(ContactUtils.getContactMap());
		map.putAll(this.environment);

		String URI = request.getRequestURI();
		URI = URI.toLowerCase();

		if (URI.contains("/admin")) {
			view = "admin/common/message";
			map.put("message", "请求无效,请稍后操作!");
		} else {
			view = "error";
		}
		ModelAndView mav = new ModelAndView(view);
		mav.addAllObjects(map);
		return mav;
	}
}